package com.androidmvp.dreammvp.simple6.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by admin on 2017/9/5.
 */

public abstract class BaseActivity_6<V extends BaseView_6,P extends BasePresenter_6> extends AppCompatActivity {

    private P presenter;
    private V view;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (this.presenter == null){
            //创建P层
            this.presenter = creatPresenter();
        }
        if (this.view == null){
            //创建V层
            this.view = creatView();
        }
        //判断是否为空
        if (this.presenter == null){
            throw new NullPointerException("presenter不能为空");
        }
        if (this.view == null){
            throw new  NullPointerException("view不能为空");
        }
        //绑定
        this.presenter.attachView(view);
    }

    public P getPresenter(){
        return presenter;
    }

    public abstract P creatPresenter();
    public abstract V creatView();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.presenter.detachView();
    }
}
